//
//  KLService.m
//  KoalaUtilKit
//
//  Created by Tommy on 15/1/4.
//  Copyright (c) 2015年 Alibaba-inc.com. All rights reserved.
//

#import "KLService.h"
#import "KLIRequest.h"
#import "KLIStrategy.h"

@implementation KLService

- (RACSignal*)fetch{
    NSAssert(0, @"");
    return nil;
}
- (RACSignal*)fetchWithParams:(NSDictionary*)params{
    NSAssert(0, @"");
    return nil;
}
- (RACSignal*)fetchWithRequest:(id<KLIRequest>)request{
    return [self startRequest:request];
}
- (RACSignal *)startRequest:(id<KLIRequest>)request{
    if(self.strategy){
        RACSignal *memRequest = [[self requestFromMemDataCenter:request] catchTo:request];
        return [RACSignal if:[self canContinueRequest:request] then:[request startRequest] else:memRequest];
    }
    return [request startRequest];
}

- (RACSignal *)canContinueRequest:(id<KLIRequest>)request{
    return [self.strategy canPassRequest:request];
}

- (RACSignal *)requestFromMemDataCenter:(id<KLIRequest>)request{
    
    return nil;
}



@end
